/**********************************************************************\
 © COPYRIGHT 2006 Corporation for National Research Initiatives (CNRI);
                        All rights reserved.
               
        The HANDLE.NET software is made available subject to the
         Handle System Public License, which may be obtained at
         http://hdl.handle.net/4263537/5030 or hdl:4263537/5030
\**********************************************************************/

package net.handle.apps.servlet_proxy.handlers;

import net.handle.hdllib.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import net.handle.apps.servlet_proxy.*;

public class Vlist implements TypeHandler {

  /** 
  * Return true iff this TypeHandler can send a redirect to the client
  * based on the given set of HandleValues.
  */
  public boolean canRedirect(HandleValue values[]) {
    return false;
  }

  /** 
  * Return true iff this TypeHandler can format the data from the given
  * HandleValue for a human client.
  */
  public boolean canFormat(HandleValue value) {
    return value.hasType(Common.STD_TYPE_HSVALLIST);
  }
  
  public String toHTML(String handle, HandleValue value){
    ValueReference[] refs;
    try {
      refs = Encoder.decodeValueReferenceList(value.getData(), 0);
      StringBuffer sb = new StringBuffer();
      for (int i=0; i<refs.length; i++){
        sb.append(Integer.toString(refs[i].index));
        sb.append(":");
        sb.append(HDLProxy.htmlEscape(Util.decodeString(refs[i].handle)));
        sb.append("<br>");
      }
      return sb.toString();
    } catch (HandleException e){
      return "?!? - Broken HS_VLIST Value - ?!?";
    }
  }

  public boolean doRedirect(HttpServletRequest request, 
                            HttpServletResponse response, HttpParams params,
                            String handle, HandleValue values[])
  {
    return false;
  }
  
}
